unit FormPesquisaAreaUnit;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids,
  JvExDBGrids, JvDBGrid, System.Actions, Vcl.ActnList;

type
  TFormPesquisaArea = class(TForm)
    EditPesquisa: TEdit;
    JvDBGrid1: TJvDBGrid;
    Label1: TLabel;
    ActionList1: TActionList;
    ActionESC: TAction;
    procedure FormCreate(Sender: TObject);
    procedure EditPesquisaChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure EditPesquisaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure JvDBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ActionESCExecute(Sender: TObject);
    procedure JvDBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    idarea : integer;
    nomearea : string;
  end;

var
  FormPesquisaArea: TFormPesquisaArea;

implementation

{$R *.dfm}

uses DMDadosUnt;

procedure TFormPesquisaArea.ActionESCExecute(Sender: TObject);
begin
  idarea := 0;
  nomearea := '';
  DMDados.dsCadastroArea.DataSet.Filtered := false;
  close;

end;

procedure TFormPesquisaArea.EditPesquisaChange(Sender: TObject);
begin

  DMDados.dsCadastroArea.DataSet.Filtered := false;

  DMDados.dsCadastroArea.DataSet.Filter := 'COD_MAPA LIKE '+QuotedStr('%'+EditPesquisa.Text+'%')+
                                           ' OR NOME LIKE'+QuotedStr('%'+EditPesquisa.Text+'%');

  DMDados.dsCadastroArea.DataSet.Filtered := true;

end;

procedure TFormPesquisaArea.EditPesquisaKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = VK_DOWN then
begin
  JvDBGrid1.SetFocus;
end;
if key = VK_RETURN then
begin
  JvDBGrid1.SetFocus;
end;
end;

procedure TFormPesquisaArea.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
DMDados.dsCadastroArea.DataSet.Filtered := False;
end;

procedure TFormPesquisaArea.FormCreate(Sender: TObject);
begin

  DMDados.cdsCadastroArea.Open;

end;

procedure TFormPesquisaArea.JvDBGrid1DblClick(Sender: TObject);
begin
  idarea   := DMDados.cdsCadastroAreaID_AREA.AsInteger;
  nomearea := DMDados.cdsCadastroAreaNOME.AsString;
  Close;
end;

procedure TFormPesquisaArea.JvDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = VK_RETURN then
  begin

    idarea   := DMDados.cdsCadastroAreaID_AREA.AsInteger;
    nomearea := DMDados.cdsCadastroAreaNOME.AsString;
    Close;


  end;
end;

end.
